dns: fix crash on setServers with port 0 - #65009
Conversation
Signed-off-by: Lazizbek Ergashev <lazerg2@gmail.com>
|
Review requested:
|
There was a problem hiding this comment.
👍
Note that this preserves the previous behaviour of crashing the process if the port was greater than INT_MAX. Indeed, even below that point, any port value greater than 65535 overflows:
> dns.setServers(['1.1.1.1:65535', '1.1.1.1:65536', '1.1.1.1:65537'])
> dns.getServers()
[ '1.1.1.1:65535', '1.1.1.1', '1.1.1.1:1' ]If you're happy, I think it would be a worthwhile addition to add validation to the port values, either as part of this PR or as a follow-up PR?
|
Thanks for the review. I couldn't reproduce the wraparound though — on this branch (c-ares 1.34.8, bundled, untouched by this diff):
Might be version-dependent on your end. Since I can't reproduce silent corruption on the current bundled c-ares, I'd rather not scope-creep this PR with |
This comment was marked as outdated.
This comment was marked as outdated.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65009 +/- ##
==========================================
- Coverage 90.29% 90.29% -0.01%
==========================================
Files 762 759 -3
Lines 247646 247605 -41
Branches 46709 46672 -37
==========================================
- Hits 223619 223564 -55
- Misses 15485 15516 +31
+ Partials 8542 8525 -17
🚀 New features to boost your workflow:
|
dns.setServers(['1.1.1.1:0'])aborts the process:SetServers()insrc/cares_wrap.ccchecked the port withCHECK(portValue->Int32Value(env->context()).FromJust()). That asserts the port value is non-zero, not that the conversion succeeded, so a port of0trips it. The family value had the same problem. Both now useMaybe::To(), like the rest of the file.c-ares already treats port 0 as "use the default port", so
1.1.1.1:0becomes1.1.1.1:53.[::1]:0behaved that way already, since the bracketed-IPv6 branch inlib/internal/dns/utils.jscoerces 0 to 53 before it ever reaches C++.Fixes: #65006